package com.glq1218.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 返回状态码
 */
@Getter
@AllArgsConstructor
public enum ResultEnum {
    SUCCESS(200, "成功"),
    DEFAULT_FAIL(500, "失败"),
    NO_PERMISSION(401, "权限不足"),
    NO_TOKEN(402, "未携带令牌"),
    USER_NOT_EXIST(403, "用户不存在"),
    USERNAME_OR_PASSWORD_ERROR(404, "用户名或密码错误"),
    NO_LOGIN(405, "未登录"), NO_LOGIN_TYPE(406, "没有登录类型");
    private final Integer code;
    private final String message;

    /**
     * 根据code获取message
     *
     * @param code code
     * @return message
     */
    public static String getMessageByCode(Integer code) {
        for (ResultEnum resultEnum : values()) {
            if (resultEnum.getCode().equals(code)) {
                return resultEnum.getMessage();
            }
        }
        return null;
    }
}
